package com.hangwei.paperless.adapter;

import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hangwei.paperless.R;
import com.hangwei.paperless.model.bean.EngTreatmentInfo;
import com.hangwei.paperless.widget.MaxRecyclerView;
import com.twelve.all.adapter.MyAdapter;
import com.twelve.all.utils.Tools;

import java.util.List;

/**
 * Created by 张龙臣 on 2020/12/16.
 */

public class EngTreatmentAdapter extends MyAdapter<EngTreatmentInfo, BaseViewHolder> {

    public EngTreatmentAdapter(@Nullable List<EngTreatmentInfo> data) {
        super(R.layout.item_eng_treatment, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, EngTreatmentInfo item) {
        TextView tvTypeName = helper.getView(R.id.tvTypeName);
        tvTypeName.setText("任务号-"+Tools.checkedString(item.woNo));
        MaxRecyclerView recyclerView = helper.getView(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(new SbuAdapter(item.dataList));
    }

    private static class SbuAdapter extends MyAdapter<EngTreatmentInfo.DataListBean,BaseViewHolder> {

        public SbuAdapter(@Nullable List<EngTreatmentInfo.DataListBean> data) {
            super(R.layout.item_item_eng,data);
        }

        @Override
        protected void convert(BaseViewHolder helper, EngTreatmentInfo.DataListBean item) {
            helper
                    .setText(R.id.tvAPN, Tools.checkedString(item.apn))
                    .setText(R.id.tvDes, Tools.checkedString(item.description))
                    .setText(R.id.tvPN, Tools.checkedString(item.pn))
                    .setText(R.id.tvSN, Tools.checkedString(item.sn))
                    .setText(R.id.tvDT, Tools.checkedString(item.discrepancyTypeName));
            SimpleDraweeView sdvStatus = helper.getView(R.id.sdvStatus);
            int pic = R.drawable.progress_writing;
            switch (item.state) {
                case 0:
                    pic = R.drawable.progress_writting_1;
                    break;
                case 1://变更中
                    pic = R.drawable.progress_changing;
                    break;
                case 2://编写完成
                    pic = R.drawable.progress_writed;
                    break;
                case 3://已审核
                    pic = R.drawable.progress_reviewed;
                    break;
                case 4://已批准
                    pic = R.drawable.progress_approved;
                    break;
                case 5://已配发
                    pic = R.drawable.progress_published;
                    break;
                case 6://填报中
                    if (item.isForInspection)
                        pic = R.drawable.progress_to_check;
                    else
                        pic = R.drawable.progress_fill;
                    break;
                case 7://提交处置中
                    pic = R.drawable.progress_eng;
                    break;
                case 8://填报完成
                    pic = R.drawable.progress_fill_finish;
                    break;
                case 9://已终止
                    pic = R.drawable.progress_stoped;
                    break;
                case 10://已归档
                    pic = R.drawable.progress_filed;
                    break;
            }
            sdvStatus.setImageURI((new Uri.Builder()).scheme("res").path(String.valueOf(pic)).build());
        }
    }
}
